package com.lsa.letcode.the100.sameTree;

import com.lsa.letcode.common.TreeNode;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null) {
        	return q == null;
        }
        else if (q == null) {
        	return false;
        }
        
        if (!isSameTree(p.left, q.left)) {
        	return false;
        }
        
        if (p.val != q.val) {
        	return false;
        }
        
        return isSameTree(p.right, q.right);
    }
}